package com.xydtech.common.config.unipush;

import com.getui.push.v2.sdk.GtApiConfiguration;
import com.getui.push.v2.sdk.api.PushApi;
import com.getui.push.v2.sdk.api.UserApi;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;

@Configuration
public class UniPushConfig {

    @Value("${unipush.appId}")
    private String appId;

    @Value("${unipush.appKey}")
    private String appKey;

    @Value("${unipush.mastersecret}")
    private String mastersecret;

    @Value("${unipush.baseUrl}")
    private String baseUrl;

    /**
     * 消息推送类型-待办
     */
    public static final String PUSH_TYPE_WAITDO = "waitdo";

    /**
     * 组装配置信息公共方法
     * @param
     * @return com.getui.push.v2.sdk.GtApiConfiguration
     * @exception
     * @author Daniel
     * @date 2021/12/28 9:44
     */
    private GtApiConfiguration buildConfig() {
        // 设置httpClient最大连接数，当并发较大时建议调大此参数。或者启动参数加上 -Dhttp.maxConnections=200
        System.setProperty("http.maxConnections", "200");
        GtApiConfiguration apiConfiguration = new GtApiConfiguration();
        //填写应用配置
        apiConfiguration.setAppId(appId);
        apiConfiguration.setAppKey(appKey);
        apiConfiguration.setMasterSecret(mastersecret);
        // 接口调用前缀，请查看文档: 接口调用规范 -> 接口前缀, 可不填写appId
        apiConfiguration.setDomain(baseUrl);
        return apiConfiguration;
    }

    /**
     * 注入pushApi对象
     * @param
     * @return com.getui.push.v2.sdk.api.PushApi
     * @exception
     * @author Daniel
     * @date 2021/12/28 9:44
     */
    //@Bean(name = "pushApi")
    public PushApi getPushApi() {
        //GtApiConfiguration apiConfiguration = buildConfig();
        //// 实例化ApiHelper对象，用于创建接口对象
        //ApiHelper apiHelper = ApiHelper.build(apiConfiguration);
        //// 创建对象，建议复用。目前有PushApi、StatisticApi、UserApi
        //PushApi pushApi = apiHelper.creatApi(PushApi.class);
        //return pushApi;
        return null;
    }

    /**
     * 注入userApi对象
     * @param
     * @return com.getui.push.v2.sdk.api.UserApi
     * @exception
     * @author Daniel
     * @date 2021/12/28 9:44
     */
    //@Bean(name = "userApi")
    public UserApi getUserApi() {
        //GtApiConfiguration apiConfiguration = buildConfig();
        //// 实例化ApiHelper对象，用于创建接口对象
        //ApiHelper apiHelper = ApiHelper.build(apiConfiguration);
        //// 创建对象，建议复用。目前有PushApi、StatisticApi、UserApi
        //UserApi userApi = apiHelper.creatApi(UserApi.class);
        //return userApi;
        return null;
    }
}
